# -*- coding:utf-8 -*-
import os
from dotenv import load_dotenv, find_dotenv
from pydantic import BaseConfig
from typing import List


class Config(BaseConfig):
    # 加载环境变量
    load_dotenv(find_dotenv(), override=True)
    # 调试模式
    APP_DEBUG: bool = False
    IS_CREATE_OPENAPI: bool = True # 是否生成openapi.json
    # 项目信息
    VERSION: str = "0.0.1"
    PROJECT_NAME: str = "fasdapi"
    DESCRIPTION: str = '<a href="/redoc" target="_blank">redoc</a>'
    # 静态资源目录
    STATIC_DIR: str = os.path.join(os.getcwd(), "static")
    # 跨域请求
    CORS_ORIGINS: List = [
        "https://pure.jvlihd.cn",
        "http://pure.jvlihd.cn",
        "http://localhost:8848",
        "http://localhost:4173"
        ]
    CORS_ALLOW_CREDENTIALS: bool = True
    CORS_ALLOW_METHODS: List = ["*"]
    CORS_ALLOW_HEADERS: List = ["*"]
    # Session
    SECRET_KEY = "fastapi_session"
    SESSION_COOKIE = "fastapi_session_id"
    SESSION_MAX_AGE = 14 * 24 * 60 * 60
    # Jwt
    JWT_SECRET_KEY = "lLNiBWPGiEmCLLR9kRGidgLY7Ac1rpSWwfGzTJpTmCU"
    JWT_SECRET_REFRESH_KEY = "lLNiBWPGiEmCLLR9kRGidgLY7Ac1rpSWwfGzTJpTmCUFASFSAFASDFA"
    JWT_ALGORITHM = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 24 * 7

    SWAGGER_UI_OAUTH2_REDIRECT_URL = "/admin/system/admin/getAccessToken"

    # 二维码过期时间
    QRCODE_EXPIRE = 60 * 1
    AUTH_PATH_EXPIRE = 60 * 10

    # 日志
    LOG_LEVEL = 'INFO'
    BACK_ADMIN_LOG_PATH = 'runtime/admin_logs/{time:YYYY-MM-DD}.log'
    API_ADMIN_LOG_PATH = 'runtime/api_logs/{time:YYYY-MM-DD}.log'

    # Redis
    REDIS_HOST = os.getenv('REDIS_HOST', '127.0.0.1')
    REDIS_PORT = os.getenv('REDIS_PORT', 6379)
    REDIS_DB = os.getenv('REDIS_DB', 0)
    REDIS_QUEUE_DB = os.getenv('REDIS_QUEUE_DB', 1)
    REDIS_LIMIT_DB = os.getenv('REDIS_LIMIT_DB', 2)
    REDIS_CHACE_DB = os.getenv('REDIS_CHACE_DB', 3)
    REDIS_EXPIRE = os.getenv('REDIS_EXPIRE', 7200)

    # MySQL
    DB_BASE_TYPE = os.getenv('DB_BASE_TYPE', 'mysql')
    DB_BASE_HOST = os.getenv('DB_BASE_HOST', '127.0.0.1')
    DB_BASE_PORT = os.getenv('DB_BASE_PORT', 3306)
    DB_BASE_DBNAME = os.getenv('DB_BASE_DBNAME', 'fastapi')
    DB_BASE_USER = os.getenv('DB_BASE_USER', 'root')
    DB_BASE_PASSWORD = os.getenv('DB_BASE_PASSWORD', '123456')

    # Robbitmq
    RABBITMQ_HOST = os.getenv('RABBITMQ_HOST', None)
    RABBITMQ_PORT = os.getenv('RABBITMQ_PORT', 5672)
    RABBITMQ_USER = os.getenv('RABBITMQ_USER', 'rabbit')
    RABBITMQ_PASSWORD = os.getenv('RABBITMQ_PASSWORD', '123456')

    # OSS
    OSS = True # 默认关闭OSS 如果开启，请再addons/Oss/config.py配置
    UPLOAD_DIRECTORY = "/uploads" # 默认上传目录
    ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif", "doc", "mp4"} # 允许上传的文件类型
    MAX_FILE_SIZE = 1024 * 1024 * 10  # 10 MB
    STATIC_PREFIX = "http://8.140.197.236:7000" #默认本地文件前缀

    # 允许的域名列表
    ALLOWED_HOSTS = ["localhost","127.0.0.1", "*"]

    # 短信配置
    SMS = {
        # aliyun 阿里云   jhsh 聚合数据
        "type": "jhsh", 
        "accessKeyId": os.getenv('SMS_ACCESS_KEY_ID', '62002222e5d2ef03d2323cfec0476b7d'),
        "accessSecret": os.getenv('SMS_ACCESS_SECRET', ''),
        "apiUrl": os.getenv('SMS_API_URL','http://v.juhe.cn/sms/send'),
        "logintemplateCode": os.getenv('SMS_LOGIN_TEMPLATE_CODE', 264580),
        "registertemplateCode":  os.getenv('SMS_REGISTER_TEMPLATE_CODE', ''),
        "forgettemplateCode": os.getenv('SMS_FORGET_TEMPLATE_CODE',''),
        "updatetemolateCode": os.getenv('SMS_UPDATE_EMPLATE_CODE')
    }



settings = Config()
